package org.lanqiao.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.lanqiao.entity.Gift;
import org.lanqiao.entity.WxuserGift;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface GiftMapper {


    @Select("SELECT g.*,wg.gift_num,DATE_FORMAT( wg.`gift_time`, '%Y-%m-%d %H:%i:%S') as `gift_time`,wg.`total_money`,a.activity_name " +
            "FROM gifts g right JOIN wxuser_gift wg ON wg.`gift_id`=g.`gift_id` left join activitys a on a.activity_id=wg.activity_id " +
            " where wg.wx_id=#{wxId}")
    public List<Map> getFGift(@Param("wxId")String wxId);


    @Select("SELECT g.*,wg.gift_num,DATE_FORMAT( wg.`gift_time`, '%Y-%m-%d %H:%i:%S') as `gift_time`,wg.`total_money`,a.activity_name " +
            "FROM gifts g right JOIN wxuser_gift wg ON wg.`gift_id`=g.`gift_id` left join activitys a on a.activity_id=wg.activity_id " +
            " where wg.wx_id=#{wxId} and a.activity_id=#{activityId}")
    public List<Map> getGiftByAll(@Param("wxId")String wxId ,@Param("activityId")String activityId);



    @Select("select *from recharge_record where wx_id=#{wxId}")
    public List<Map> getRecords(@Param("wxId")String wxId);

    /**
     * 根据活动id查询所有礼物
     *
     * @return
     */
    @Select("SELECT g.*,u.wx_name,wg.gift_num,DATE_FORMAT( wg.`gift_time`, '%Y-%m-%d %H:%i:%S') as `gift_time`,wg.`total_money`,a.activity_name " +
            "FROM gifts g right JOIN wxuser_gift wg ON wg.`gift_id`=g.`gift_id` right join activitys a on a.activity_id=wg.activity_id " +
            " left join wxusers u on u.wx_id=wg.wx_id where  a.activity_id=#{acId}")
    public List<Map> getGiftByActivityId(@Param("acId") String acId);


    /*
     * 查询所有礼物信息
     * */
    List<Gift> selectAllGift();
}